Skip to content

GH-44713: [Python] Add support for Decimal32 and Decimal64 types - #44882

Merged
paleolimbot merged 18 commits into
apache:mainfrom
paleolimbot:pyarrow-decimal3264
Dec 17, 2024
Merged

GH-44713: [Python] Add support for Decimal32 and Decimal64 types#44882
paleolimbot merged 18 commits into
apache:mainfrom
paleolimbot:pyarrow-decimal3264

Conversation

@paleolimbot

@paleolimbot paleolimbot commented Nov 28, 2024

Copy link
Copy Markdown
Member

Rationale for this change

Arrow C++ and the Arrow specification now support 32-bit and 64-bit decimal types...pyarrow should too!

What changes are included in this PR?

Added type, array, and scalar bindings.

Are these changes tested?

Yes!

Are there any user-facing changes?

Yes!

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #44713 has been automatically assigned in GitHub to PR creator.

@ianmcook

ianmcook commented Nov 29, 2024

Copy link
Copy Markdown
Member

Please add the concrete classes for the scalars to the list under the Scalars heading in arrays.rst.

And after you add the is_ methods, please add those under the Type Checking heading in datatypes.rst.

Thanks!

@paleolimbot

Copy link
Copy Markdown
Member Author

Current battles (so I remember them Monday!):

I'm missing some member definition for the use-facing type classes:

import pyarrow as pa

pa.decimal128(2, 0).precision
#> 2
pa.decimal256(2, 0).precision
#> 2
pa.decimal32(2, 0).precision
#> AttributeError: 'pyarrow.lib.Decimal32Type' object has no attribute 'precision'

There's no cast implemented from "float" to "decimal32/64", which at least some of the tests depend on:

pyarrow.lib.ArrowNotImplementedError: Unsupported cast to decimal32(7, -8) from float

Comment thread python/pyarrow/__init__.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to add Decimal32Array, Decimal64Array to line 220 and Decimal32Scalar, Decimal64Scalar to line 229

@github-actions github-actions Bot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Dec 11, 2024
Comment thread python/pyarrow/types.pxi Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should update to between 1 and 18

Comment thread python/pyarrow/tests/test_compute.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be 9, not 8?

@paleolimbot

Copy link
Copy Markdown
Member Author

Ok! I think this just needs #45014 .

zeroshade added a commit that referenced this pull request Dec 13, 2024
<!--
Thanks for opening a pull request!
If this is your first pull request you can find detailed information on
how
to contribute here:
* [New Contributor's
Guide](https://arrow.apache.org/docs/dev/developers/guide/step_by_step/pr_lifecycle.html#reviews-and-merge-of-the-pull-request)
* [Contributing
Overview](https://arrow.apache.org/docs/dev/developers/overview.html)


If this is not a [minor
PR](https://github.com/apache/arrow/blob/main/CONTRIBUTING.md#Minor-Fixes).
Could you open an issue for this pull request on GitHub?
https://github.com/apache/arrow/issues/new/choose

Opening GitHub issues ahead of time contributes to the
[Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.)
of the Apache Arrow project.

Then could you also rename the pull request title in the following
format?

    GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}

or

    MINOR: [${COMPONENT}] ${SUMMARY}

-->

### Rationale for this change
Furthering the support for Decimal32/Decimal64 among Acero and casting
functionality. This is also necessary for #44882 to add support for
Decimal32/64 to PyArrow

<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->

### What changes are included in this PR?
Adding kernels for casting to and from Decimal32/Decimal64 between
numeric, floating point, string and other decimal types.

<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->

### Are these changes tested?
Yes, unit tests are added accordingly.

<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code

If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->

* GitHub Issue: #43956
@paleolimbot
paleolimbot marked this pull request as ready for review December 13, 2024 17:04
@github-actions github-actions Bot added awaiting merge Awaiting merge and removed awaiting change review Awaiting change review labels Dec 13, 2024

@raulcd raulcd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are tests and documentation finished? Just wondering if the description of the PR has to be updated or is there something missing that is expected to be followed up on a subsequent PR

@github-actions github-actions Bot added awaiting changes Awaiting changes and removed awaiting merge Awaiting merge labels Dec 16, 2024
@paleolimbot

Copy link
Copy Markdown
Member Author

@raulcd Sorry, I should have updated that. I've updated documentation and tests accordingly already!

@pitrou

pitrou commented Dec 16, 2024

Copy link
Copy Markdown
Member

@github-actions crossbow submit -g python

@pitrou pitrou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I just wonder if the hypothesis tests pass

@github-actions

Copy link
Copy Markdown

Revision: e4ff26e

Submitted crossbow builds: ursacomputing/crossbow @ actions-c539869415

Task Status
example-python-minimal-build-fedora-conda GitHub Actions
example-python-minimal-build-ubuntu-venv GitHub Actions
test-conda-python-3.10 GitHub Actions
test-conda-python-3.10-cython2 GitHub Actions
test-conda-python-3.10-hdfs-2.9.2 GitHub Actions
test-conda-python-3.10-hdfs-3.2.1 GitHub Actions
test-conda-python-3.10-pandas-latest-numpy-latest GitHub Actions
test-conda-python-3.10-substrait GitHub Actions
test-conda-python-3.11 GitHub Actions
test-conda-python-3.11-dask-latest GitHub Actions
test-conda-python-3.11-dask-upstream_devel GitHub Actions
test-conda-python-3.11-hypothesis GitHub Actions
test-conda-python-3.11-pandas-latest-numpy-1.26 GitHub Actions
test-conda-python-3.11-pandas-latest-numpy-latest GitHub Actions
test-conda-python-3.11-pandas-nightly-numpy-nightly GitHub Actions
test-conda-python-3.11-pandas-upstream_devel-numpy-nightly GitHub Actions
test-conda-python-3.11-spark-master GitHub Actions
test-conda-python-3.12 GitHub Actions
test-conda-python-3.12-cpython-debug GitHub Actions
test-conda-python-3.13 GitHub Actions
test-conda-python-3.9 GitHub Actions
test-conda-python-3.9-pandas-1.1.3-numpy-1.19.5 GitHub Actions
test-conda-python-emscripten GitHub Actions
test-cuda-python-ubuntu-22.04-cuda-11.7.1 GitHub Actions
test-debian-12-python-3-amd64 GitHub Actions
test-debian-12-python-3-i386 GitHub Actions
test-fedora-39-python-3 GitHub Actions
test-ubuntu-22.04-python-3 GitHub Actions
test-ubuntu-22.04-python-313-freethreading GitHub Actions
test-ubuntu-24.04-python-3 GitHub Actions

@pitrou

pitrou commented Dec 16, 2024

Copy link
Copy Markdown
Member

The CI failures are unrelated. You might want to wait for @jorisvandenbossche 's review, but you can merge as well.

@paleolimbot
paleolimbot merged commit 2fcf8b3 into apache:main Dec 17, 2024
@paleolimbot paleolimbot removed the awaiting changes Awaiting changes label Dec 17, 2024
@paleolimbot

Copy link
Copy Markdown
Member Author

Thank you for taking a look!

@paleolimbot
paleolimbot deleted the pyarrow-decimal3264 branch January 9, 2025 15:54
@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 3 benchmarking runs that have been run so far on merge-commit 2fcf8b3.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants